package pers.ht.mbpo.service;

import net.sf.json.JSONArray;
import pers.ht.mbpo.bean.BusCarReturn;
import pers.ht.mbpo.dao.BusCarDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created by HbunSE on 2019/5/31.
 */
@WebServlet("/BusCarFirstServlet")
public class BusCarFirstServlet extends HttpServlet {
    private BusCarDao bDao = new BusCarDao();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, DELETE,PUT,GET,OPTIONS");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.addHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/xml");
        response.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        String time = request.getParameter("time");
        String carid = request.getParameter("carid");
        String busLineName = request.getParameter("busLineName");
        String updown = request.getParameter("updown");
        List<BusCarReturn> carList = bDao.queryFirst(time, busLineName, updown);
        String scoreJson = JSONArray.fromObject(carList).toString();
        out.print(scoreJson);
    }
}
